angular.module('starter.services', [])
.service("appService",function(){
	var appServiceFactory = {};

	//检查输入框是否有输入来显示取消按钮与隐藏函数
	var inputchangeFn = function($scope,obj1,obj2){
		//检测输入框是否输入
	    $scope.inputChange = function(){
			var conChange = obj1.val();
			var undo = obj2;
			if(conChange == ""){
				undo.hide();
				$scope.focus = function(){
					undo.hide();
				}
				$scope.blur = function(){
					undo.hide();
				}
			}else{
				undo.show();
				$scope.focus = function(){
					undo.show();
				}
				$scope.blur = function(){
					undo.hide();
				}
			}
		}
	    //点击取消按钮删除输入框内容
		$scope.undoFn = function(){
			obj1.val("");
			obj2.hide();
		}
	}
	
	var timeFn = function(s,obj){//进入页面开始倒计时
		if (s == 0) {
			obj.removeAttr("disabled");
			obj.val("重新发送");
			s = 60;
		}else{
			obj.attr("disabled","true");
			obj.val(s + "秒");
			s --;
			setTimeout(function  () {
				timeFn(s,obj);
			},1000)
		}
	}
	
	appServiceFactory.inputchangeFn = inputchangeFn;
	appServiceFactory.timeFn = timeFn;
	
	return appServiceFactory;
})